<template>
	<view>
		<z-paging style="height: 100% !important;" class="wrap" ref="paging" v-model="dataList" @query="queryList" :refresher-enabled="false">
			<view class="wrap">
					<cu-custom bgColor="bg-gradual-blue" :isBack="true">
						<block slot="backText">返回</block>
						<block slot="content">维修经验库</block>
					</cu-custom>
					
					<!-- 头部结束 -->
					<view slot="top" class="search">
						<u-search placeholder="请输入计划名称" v-model="getData.KeyWords" @custom='search()' @search='search()'></u-search>
					</view>
					<view style="width: 100%;height: 80rpx;background-color: white;margin-top: 10rpx;" class="classify">
						<text @click="getQrcodeTree()" style="margin-right: 140rpx;">
							{{(chooseNames!=null&&chooseNames!='')?chooseNames:'请选择分类'}}
							<text class="bxImg cuIcon-unfold" style="margin-right: 10rpx;height: 18rpx;width: 18rpx;"></text>
						</text>
						<text @click="showQrcodeSelect()">
							{{(chooseQrcodeNames!=null&&chooseQrcodeNames!='')?chooseQrcodeNames:'请选择点位'}}
							<text class="bxImg cuIcon-unfold" style="margin-right: 10rpx;height: 18rpx;width: 18rpx;"></text>
						</text>
						<text @click="removeFiltes()" class="removeFiltes">清空</text>
					</view>
					<pickerSearch v-model="qrcodeSeleceShow" :dataSource='qrcodeArry' :pickerValues="[0]" @recload='confirmQrcode'></pickerSearch>
					<view v-for="(item, index) in dataList" class="goods-item-wrap" :class="item.isNowTask==1?'goods-item-wrap-now':''">
						<view class="goods-content-wrap">
							<view class="goods-name">
								<view class="goods-name-title">{{item.Title}}</view>
							</view>
							<view class="goods-stock-wrap">
								<view class="goods-stock">经验描述</view>
								<view class="goods-stock">{{item.Faultesc}}</view>
							</view>
							<view class="goods-stock-wrap">
								<view class="goods-stock">创建时间</view>
								<view class="goods-stock">{{item.AddTime}}</view>
							</view>
						    <view class="goods-stock-wrap" style="border-bottom: 1px solid #F3F4F8;">
								<view  v-if="item.FaultType==1"  class="goods-stock">通用经验</view>
								<view  v-if="item.FaultType==2"  class="goods-stock">所属分类</view>
								<view  v-if="item.FaultType==3"  class="goods-stock">所属点位</view>
								<view class="goods-stock-time">{{item.FaultTypeName}}</view>
							</view>
							<view v-if="item.FaultType==1" class="goods-price1">通用故障</view>
							<view v-if="item.FaultType==2" class="goods-price2">分类专属</view>
							<view v-if="item.FaultType==3" class="goods-price3">设备专属</view>
							<view class="publish-goods-btn" @click="goDetail(item.Id)">查看</view>
						</view>
					</view>
					<view style="width: 100%;height: 40rpx"></view>
			</view>
			<ba-tree-picker ref="treePicker" :multiple='false' :showAll='true' @select-change="selectAssign" title="分类筛选"
				 :localdata="treeQrcodeList" valueKey="id" textKey="name" childrenKey="children" />
		</z-paging>
	</view>
</template>

<script>
import request from '@/common/request.js';
import unifab from "@/components/beyondGod-drag/beyoundGod-drag.vue";
import pickerSearch from "@/components/picker-search/pickerSearch.vue";
export default {
	components: {
			unifab,pickerSearch
		},
	data() {
		return {
			chooseNames:'',
			chooseQrcodeNames:'',
			chooseQrcodeId:'',
			treeQrcodeList:[],
			scrollLeft: 0,
			count:{
				task1:0,
				task2:0,
				task3:0,
				task5:0,
				task6:0,
			},
			themeColor: '#0079FE',
			authMessage:'',
			activeColor: '#0081ff',
			getData:{
				KeyWords:'',
				ClassId:'',
				QrcodeId:'',
				PageIndex:'1',
				PageSize:'10'
			},
			dataList:[],
			current: 0,
			swiperCurrent: 0,
			tabsHeight: 0,
			dx: 0,
			goodsNav: 1,
			showDaiBan:0,
			showWorkOrder:0,
			qrcodeSeleceShow: false,
			qrcodeArry: [],
			requestData:{
				JobId:'',
				Longitude:'',
				Latitude:'',
				Desc:'',
				QrcodeId:'',
				SceneType:'',
				Images:[],
				Video:'',
				CustomFields:'',
				DeviceId:'',
				Phone:''
			},
		};
	},
	mounted() {
		console.log('mounted')
	},
	computed: {
	},
	onLoad() {
		let that=this
		that.queryList(1,10);
		that.getQrcodeList()
	},
	onShow(){
	},
	onHide() {
	},
	methods: {
		goDetail(id){
			uni.navigateTo({
				url: '/pages-others/fault/faultdetail?id='+id
			})
		},
		removeFiltes(){
			let that=this
			that.chooseQrcodeNames=''
			that.getData.QrcodeId=''
			that.chooseNames=''
			that.getData.ClassId=''
			that.goodsList=[]
			that.queryList(1,10)
		},
		cancelQrcode(){
			console.log('cancelQrcode')
		},
		confirmQrcode(data) {
			let that=this
			that.chooseQrcodeNames=data.name
			that.getData.QrcodeId=data.id
			that.queryList(1,10);
		},
		showQrcodeSelect(){
			let that=this
			that.qrcodeSeleceShow=true
		},
		getQrcodeList(){
			let that=this
			that.qrcodeArry=[]
			let opts = {
				url: 'api/GetLatelyQrcode',
				method: 'get'
			};
			request.httpTokenRequest(opts,that.requestData).then(res => {
				if(res.data.code == 1){
					if(res.data.data.length>0){
						
						for(let i = 0; i < res.data.data.length; i++) {
							let data = res.data.data[i];
							let listdata={}
							listdata.id=res.data.data[i].Id
							listdata.name=res.data.data[i].qrcode_title
							that.qrcodeArry.push(listdata)
						}
					}
				}
				else{
					uni.showToast({ title: res.data.msg, icon: 'none' });
				}
			});
		},
		getQrcodeTree(){
			var that = this;
			uni.showLoading({
				title: '加载中...'
			})
			let opts = {
				url: 'SpareApi/GetZtreeDepartmentList',
				method: 'get'
			};
			request.httpTokenRequest(opts).then(res => {
				uni.hideLoading();
				if(res.data.code == 1){
					that.treeQrcodeList=res.data.data
					this.$refs.treePicker._show();
				}
				else{
					uni.showToast({ title: res.data.msg, icon: 'none' });
				}
			});
		},
		selectAssign(ids){
			let that=this
			if(ids.length==0){
				uni.showToast({ title:'请选择点位分类', icon: 'none' });
				this.$refs.treePicker._show();
			}else{
				console.log('checkIds:'+JSON.stringify(ids))
				that.chooseNames=''
				for(let i=0;i<ids.length;i++){
					let entity=ids[i]
					that.chooseNames=entity.name+','+that.chooseNames
				}
				that.chooseNames=that.chooseNames.substring(0,that.chooseNames.length-1)
				that.getData.ClassId=ids[0].id
				that.goodsList=[]
				that.queryList(1,10)
			}
		},
		queryList(pageNo, pageSize) {
			console.log('queryList')
			var that = this;
			uni.showLoading({
				title: '加载中...'
			})
			let opts = {
				url: 'api/GetQrcodeFaultList',
				method: 'get'
			};
			that.getData.PageIndex=pageNo;
			that.getData.PageSize=pageSize;
			request.httpTokenRequest(opts,that.getData).then(res => {
				if(res.data.code == 1){
					this.$refs.paging.complete(res.data.data.list);
					uni.hideLoading();
				}
				else{
					uni.showToast({ title: res.data.msg, icon: 'none' });
				}
			});
		},
		// 搜索框
		search(e){
			let that=this
			that.getData.KeyWords=e
			this.queryList(1,10);
		},
	}
};
</script>

<style lang="scss" scoped>
/* #ifndef H5 */
page {
	height: 100%;
	background-color: #f2f2f2;
}
/* #endif */
</style>

<style lang="scss" scoped>
	.removeFiltes{
		position: absolute;
		right: 20rpx;
		font-size: 26rpx;
		color: #F5222D;
		line-height:80rpx;
	}
	.cu-tag.badge{
		top:-10rpx !important;
		right:30rpx !important;
		
	}
	.goods-item-wrap-now{
		//border:2px solid #00B52A;
	}
	.goods-item-wrap {
		border-radius: 8rpx;
		background: #FFFFFF;
		display: flex;
		padding: 24rpx;
		margin: 12rpx;
		//width:100%;
		.goods-content-wrap{
			width: 100%;
		}
		.goods-name {
			width: 100%;
			font-size: 32rpx;
			font-weight: bold;
			display: flex;
			position: relative;
			border-bottom: 1px solid #F3F4F8;
			padding-bottom: 20rpx;
		}
		.goods-name-title{
			display: block;
			float: left;
		}
		.goods-name-type{
			display: block;
			float:right;
			color: #3B69FD;
			margin-right: 20rpx;
		}
		.goods-stock-wrap {
			display: flex;
			color: #969696;
			font-size: 24rpx;
			margin-top: 20rpx;
		}
		
		.goods-stock {
			margin-right: 40rpx;
			font-size: 28rpx;
			color: #636571;
			line-height: 32rpx;
		}
		.goods-stock-isok{
			margin-right: 10rpx;
			font-size: 38rpx;
			color: #00B52A;
			line-height: 32rpx;
			font-weight: 700;
		}
		.goods-stock-middle{
			margin-right: 10rpx;
			font-size: 38rpx;
			color: #636571;
			line-height: 32rpx;
			font-weight: 700;
		}
		.goods-stock-notok{
			margin-right: 40rpx;
			font-size: 38rpx;
			color: #F53F3E;
			line-height: 32rpx;
			font-weight: 700;
		}
		.goods-stock-time {
			margin-right: 24rpx;
			font-size: 28rpx;
			color: #e7612e;
			padding-bottom: 20rpx;
		}
		.goods-shangxiaxian {
			font-size:24rpx;
			color: #3F71C4;
			margin-top: 14rpx;
		}
		
		.goods-price1 {
			font-size:26rpx;
			color: #3B69FD;
			margin-top: 20rpx;
			font-weight:500;
			width: 160rpx;
			display: block;
			float:left;
			background-color: #D0D9F7;
			border-radius: 4rpx;
			text-align: center;
			height: 54rpx;
			line-height: 54rpx;
		}
		.goods-price2 {
			font-size:26rpx;
			color: #15C9CA;
			margin-top: 20rpx;
			font-weight:500;
			width: 160rpx;
			display: block;
			float:left;
			background-color: #C8ECEC;
			border-radius: 4rpx;
			text-align: center;
			height: 54rpx;
			line-height: 54rpx;
		}
		.goods-price3 {
			font-size:26rpx;
			color: #F39C12;
			margin-top: 20rpx;
			font-weight:500;
			width: 160rpx;
			display: block;
			float:left;
			background-color: #F4EAD9;
			border-radius: 4rpx;
			text-align: center;
			height: 54rpx;
			line-height: 54rpx;
		}
		.goods-option-item {
			padding: 8rpx 16rpx;
			border-radius: 36rpx;
			font-size: 24rpx;
			margin-top: 24rpx;
		}
	}
	
.wrap {
	display: flex;
	flex-direction: column;
	height: calc(120vh - var(--window-top));
	width: 100%;
}
.swiper-box {
	flex: 1;
}
.swiper-item {
	height: 100%;
}

	.goods-option-item {
		padding: 8rpx 16rpx;
		border-radius: 36rpx;
		font-size: 24rpx;
		margin-top: 24rpx;
	}

	.goods-option-item:not(:last-child) {
		margin-right: 24rpx;
	}

	.goods-option-item-action {
		background: #f1f0fe;
		color: #6991ce;
	}

	.goods-item-wrap {
		margin-top: 24rpx;
	}

	.goods-header-wrap {
		display: flex;
		align-items: center;
		padding: 24rpx;
		background: #FFFFFF;
		margin-bottom: 10rpx;
	}
	.goods-header-item{
		width:33%;
		text-align: center;
	}
	.goods-header-item-active{
		font-size: 28rpx;
		font-color: #333333;
		font-weight: bold;
		position: relative;
	}
	.goods-header-item-active::after{
		position: absolute;
		left: 50%;
		right: 0;
		background: #4372fe;
		height: 8rpx;
		content: "";
		bottom: -12rpx;
		width: 60rpx;
		margin-left: -30rpx;
		border-radius: 200rpx;
	}
	.goods-header-item-action {
		// font-size: 32rpx;
		// font-color: #333333;
		// font-weight: bold;
		position: relative;
	}

	.goods-header-item-action::after {
		// position: absolute;
		// left: 0;
		// right: 0;
		// background: #4372fe;
		// height: 8rpx;
		// content: "";
		// bottom: -12rpx;
	}
	.extraPosition{
		position: absolute;
		right: -5rpx;
		top: -10rpx;
		font-size: 20rpx;
		padding: 0rpx 10rpx;
		height: 28rpx;
		color: #ffffff;
		background-color: #dd514c;
		display: inline-flex;
		align-items: center;
		justify-content: center;
	}
	
	.publish-goods-btn {
		width:160rpx;
		background: #e7612e;
		color: #FFFFFF;
		height: 54rpx;
		line-height: 54rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 82rpx;
		float:right;
		margin-right: 20rpx;
		margin-top: 20rpx;
	}
	
	.publish-goods-btn1 {
		width:160rpx;
		background: #3B69FD;
		color: #FFFFFF;
		height: 54rpx;
		line-height: 54rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 82rpx;
		float:right;
		margin-right: 20rpx;
		margin-top: 20rpx;
	}
	.search{
		width: 100%;
		height: 100rpx;
		padding: 20rpx 2% 20rpx 2%;
		background-color: #fff;
		// display: flex;
		// align-items: center;
	}
	
	.classify{
		display: flex;
		justify-content: center;
		align-items: center;
		min-height: 80rpx;  /* 设置最小高度，避免被压缩 */
		padding-top: 10rpx;
		padding-bottom: 10rpx;
		background-color: white;
	}
	
	.zp-l-container{
		display:none !important;
	}
</style>

